<?php
include 'islogin.php';
include '../config.php';

if(isset($_GET['flag']))
{

	if($_GET['flag']=='del')
	{
		$sql = "update en_download set flag =0 where id=".$_GET['down_id'];
		mysql_query($sql);
	}
}
if(isset($_GET["id"]))
{
	$pro_id = $_GET["id"];//产品ID
}

if(isset($_POST['flag']))
{
	if($_POST['flag']=='add')
	{
		$pro_id = $_POST["pro_id"];//产品ID
	}
	$dates = date("Y-m-d");
	$sql = "insert into en_download(name,url,remark,counts,dates,type_,pro_id,description,flag,size) 
	values('".$_POST['name']."','".$_POST['url']."','".$_POST['remark']."', ".$_POST['counts'].",'".$dates."',".$_POST['type_'].",".$_POST['pro_id'].",'".$_POST['description']."',1,'".$_POST['size']."')";
	mysql_query($sql);
}

$sql = "select a.id,a.name,a.model,a.type_id,a.price,a.path,a.remark,a.content,a.dates,a.ishot,a.isnews,b.name as type_name from en_product as a inner join en_pro_type as b on a.type_id=b.id  where a.flag =1 and a.id=".$pro_id;
$result = mysql_query($sql);
$row = mysql_fetch_array($result);


?>
<script src="../js/jquery-1.7.1.js"></script>
<link href="images/skin.css" rel="stylesheet" type="text/css" />
<link href="css/right.css" rel="stylesheet" type="text/css"/>
<link href="js/upload/uploadify.css" rel="stylesheet" type="text/css" />
<script src="js/upload/swfobject.js"></script>
<script src="js/upload/jquery.uploadify.v2.1.4.min.js"></script>
<style>
   #img_uploadUploader{vertical-align:middle}
</style>
<script>
function mouseoverTD(obj)
{
	   $(obj).css("background","#aaa");
}
function mouseoutTD(obj)
{
	  $(obj).css("background","");
}

function del(id,obj)
{
	  if(confirm("是否要删除此下载文件？"))
	  {
		  var url = "downloadAdd.php?flag=del&id=<?php echo $pro_id;?>&down_id="+id;
		  
		  window.location.href=url;
	  }
	  
}
$(document).ready(function(){

	   $('#img_upload').uploadify({
		   'uploader':'js/upload/uploadify.swf',
		   'cancelImg':'js/upload/cancel.png',
		   'fileExt':'*.png',
		   'script':'file_upload.php',
		   'auto':true,
		   'folder':'upload',
		   'buttonImg':'images/Browse.png',
		   'width':70,
		   'height':25,
		   'wmode':'transparent',
		   'onComplete':function(event,queueId,fileObj,response,data){
			   	 
			     $("#url").val(fileObj.filePath);
			     $("#size").val(fileObj.size);
			   }
	});
});
</script>
<div style="border:0px solid red;"> 

    	<div id="top"><div>相关下载</div></div>
    	
	    <div id="middle">
	     <div class="layout">
		  	<div class="title"><font color="red"><?php echo $row["name"];?>(<?php echo $row["model"];?>)</font>的所有下载内容</div>
		       <div class="content">
			      	 <table  cellspacing="0" cellpadding="0">  
			   				<tr >
				   		   		<td class="title_some_td" style="width:300px; text-align:center;">名称</td>
				   		   		<td class="title_some_td" style="width:100px; text-align:center;">日期</td>
				   		   		<td class="title_some_td" style="width:100px; text-align:center;">类型</td>
				   		   		<td class="title_some_td" style="width:100px; text-align:center;">操作</td>
				   		   </tr>
				   		   <?php 
				   		   		$sql = "select a.id,a.name,a.url,a.remark,a.counts,a.dates,b.name as type_name from en_download as a inner join en_download_type as b on a.type_=b.id  where a.flag =1 and a.pro_id=".$pro_id;
				   		   		$result = mysql_query($sql);
				   		   		
				   		   		while($row = mysql_fetch_array($result))
				   		   		{
				   		   	?>
				   		   		<tr style='cursor:pointer;'  onmouseover='mouseoverTD(this)' onmouseout='mouseoutTD(this)'>
				   		   			<td class="context_td" style="width:100px; text-align:center;"><?php echo $row['name'];?></td>
				   		   			<td class="context_td" style="width:100px; text-align:center;"><?php echo $row['dates'];?></td>
				   		   			<td class="context_td" style="width:100px; text-align:center;"><?php echo $row['type_name'];?></td>
				   		   			<td class="context_td" style="width:100px; text-align:center;">
				   		   			<a style='text-decoration:underline;' href='javascript:return false;' onclick="del('<?php echo $row['id']?>',this)">删除</a>
				   		   	
				   		   			<a style='text-decoration:underline;' href='downloadUpdate.php?flag=update&id=<?php echo $row['id']?>'>修改</a>
				   		   			<a style='text-decoration:underline;' href='<?php echo $row['url']?>'>下载</a>
				   		   			</td>
				   		   		</tr>
				   		   	
				   		   	<?php
				   		   		}
				   		   ?>
				  </table> 		   
		      </div>
		  </div>
		  <div class="layout">
		  		<div class="title">新增下载</div>
		  		<div class="content">
		  			<form action="downloadAdd.php" method="post">
		  			 <input type="hidden" name="flag" value="add" />
			         <input type="hidden" name="pro_id" value="<?php echo $pro_id;?>" />
			  			<table  cellspacing="0" cellpadding="0">  
				          	<tr>
				          		<td class="title_some_td" style="width:100px;">名称:</td>
				          		<td><input name="name" value=""  /></td>
				          	</tr>
				          	
				          	<tr>
				          		<td class="title_some_td" style="width:100px;">下载文件:</td>
				          		<td  style="width:300px;"><input id="url" name="url" value=""  /> <input id="img_upload" /></td>
				          	</tr>
				          	
				          	<tr>
				          		<td class="title_some_td" style="width:100px;">文件大小:</td>
				          		<td><input id="size" name="size" value=""  />byte(字节)</td>
				          	</tr>
				          	<tr>
				          		<td class="title_some_td" style="width:100px;">下载类型:</td>
				          		<td>
				          		<?php $type_id=1;?>
				          			<select name="type_">
				          				<?php include 'select_downloadType.php';?>
				          			</select>
				          		</td>
				          	</tr>
				          	<tr>
				          		<td class="title_some_td" style="width:100px;">版本:</td>
				          		<td><input id="remark" name="remark" value=""  /></td>
				          	</tr>
				          	<tr>
				          		<td class="title_some_td" style="width:100px;">初始下载次数:</td>
				          		<td><input id="counts" name="counts" value="0"  /></td>
				          	</tr>
				          	<tr>
                                <td class="title_some_td" style="width:100px;">说明:</td>
                                <td><textarea name="description" style="width:200px; height:100px;"></textarea></td>
                            </tr>
				          	<tr>
			          		<td></td>
			          		<td><input type="submit" value="保存" /></td>
			          	</tr>
				         </table> 
			        </form> 	
		  		</div>
		  </div>
	    </div>
	    
	    <div id="bottom"></div>		
</div>	    